import 'package:flutter/cupertino.dart';
import 'package:flutter/services.dart';
import 'package:path/path.dart' as p;

class AnimalDataTool {
  static Map<String, List<Map<String,dynamic>>> animalMap = <String, List<Map<String,dynamic>>>{};
  static bool loadAnimalDataDone = false;

  static loadAnimalFiles() {
    final manifestContent = rootBundle.loadString('text/files.txt').then((manifestContent) async {
      var afs = manifestContent.split("\n");
      animalMap.clear();
      for (var af in afs) {
        String pathFile = "text/animals/${af}";
        final animalPrefix2 = p.basenameWithoutExtension(pathFile);
        var animalLines = await rootBundle.loadString(pathFile);
        var animalItems = animalLines.split("\n");
        List<Map<String,dynamic>> animalPrefix2List = [];
        for (var animalItem in animalItems) {
          var ainfo = animalItem.split(",");
          var name = ainfo[0];
          var id = ainfo[1];
          animalPrefix2List.add({"id": id, "name": name});
        }
        animalMap[animalPrefix2] = animalPrefix2List;
      }
      loadAnimalDataDone = true;
      debugPrint("load animal info done");
    });
  }



}


class SearchParams {
  final String text;
  final Map<String, List<Map<String, dynamic>>> animalMap;
  SearchParams(this.text, this.animalMap);
}